<template>
	<section>		
		<el-col :span="24">
			<el-breadcrumb separator=">">
			  <el-breadcrumb-item :to="{ path: '/coursetask?id='+$route.query.id }">作业批改</el-breadcrumb-item>		  
			  <el-breadcrumb-item>{{UnitInfo.name}}</el-breadcrumb-item>
			</el-breadcrumb>			
		</el-col>
		<div v-if="$route.query.stage==1||$route.query.stage==2">				
			<el-col :span="24">
				<h1 style="text-align: center;margin: 20px 0;font-size:18px;">{{UnitInfo.name}}</h1>
				<el-table :data="List" style="width: 100%"> 
					<el-table-column  type="index" width='80'>
					</el-table-column>						 	
				 	<el-table-column prop="user.realName" label="学生姓名">
				    </el-table-column>
				 	<el-table-column prop="user.phone" label="手机号">
				    </el-table-column>
				 	<el-table-column prop="commitTime" label="作业提交时间">
				    </el-table-column>
				 	<el-table-column prop="publishTime" label="作业评分时间">
				    </el-table-column>
				 	<el-table-column prop="isCommitted" label="提交状态">
				 		<template scope="scope">
				 			<p>{{scope.row.isCommitted?'已提交':'未提交'}}</p>
				 		</template>
				    </el-table-column>		
				 	<el-table-column prop="isPublished" label="评分状态">
				 		<template scope="scope">
				 			<p>{{scope.row.isPublished?'已评分':'未评分'}}</p>
				 		</template>				 		
				    </el-table-column>	
				 	<el-table-column prop="unitScore" label="分数">
				   </el-table-column>	
					<el-table-column label="操作">
						<template scope="scope">
							<el-button size="small" v-if="scope.row.isCommitted&&!scope.row.isPublished" @click="skip('/taskstage',$route.query.id,scope.row.unitId,'1',scope.row.user.userId,scope.row)" type="warning">评分</el-button>
							<el-button size="small" v-if="scope.row.isPublished&&scope.row.isCommitted"  @click="skip('/taskstage',$route.query.id,scope.row.unitId,'1',scope.row.user.userId,scope.row)" type="danger">已评分</el-button>	
							<el-button size="small" v-if="!scope.row.isCommitted"   type="success">未提交</el-button>		
						</template>					
					</el-table-column>
				</el-table>				
			</el-col>
			<!--工具-->
			<el-col :span="24" class="toolbar">
				<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="10" :total="total" style="float:right;">
				</el-pagination>
			</el-col>				
		</div>
		<div v-if="$route.query.stage==3||$route.query.stage==4">				
			<el-col :span="24" v-show="$route.query.stage==3">
				<h1 style="text-align: center;margin: 20px 0;font-size:18px;">{{UnitInfo.name}}</h1>
				<el-table :data="teamList"  style="width: 100%"> 
					<el-table-column  type="index" width='80'>
					</el-table-column>						 	
				 	<el-table-column prop="name" label="小组">
				    </el-table-column>
				 	<el-table-column prop="inferCommitTime" label="作业提交时间">
				    </el-table-column>
				 	<el-table-column prop="inferPublishTime" label="作业评分时间">
				    </el-table-column>
				 	<el-table-column prop="isInferCommitted" label="提交状态">
				 		<template scope="scope">
				 			<p>{{scope.row.isInferCommitted?'已提交':'未提交'}}</p>
				 		</template>
				    </el-table-column>		
				 	<el-table-column prop="isInferPublished" label="评分状态">
				 		<template scope="scope">
				 			<p>{{scope.row.isInferPublished?'已评分':'未评分'}}</p>
				 		</template>				 		
				    </el-table-column>	
				 	<el-table-column prop="inferScore" label="分数">
				   </el-table-column>	
					<el-table-column label="操作">
						<template scope="scope">
							<el-button size="small"  v-if="scope.row.isInferCommitted&&!scope.row.isInferPublished" @click="Roadskip('/taskstage',$route.query.id,scope.row.teamId,'3',scope.row)" type="warning">评分</el-button>
							<el-button size="small" v-if="scope.row.isInferPublished&&scope.row.isInferCommitted" @click="Roadskip('/taskstage',$route.query.id,scope.row.teamId,'3',scope.row)" type="danger">已评分</el-button>	
							<el-button size="small" v-if="!scope.row.isInferCommitted"   type="success">未提交</el-button>								
						</template>					
					</el-table-column>
				</el-table>				
			</el-col>
			<el-col :span="24" v-show="$route.query.stage==4">
				<h1 style="text-align: center;margin: 20px 0;font-size:18px;">{{UnitInfo.name}}</h1>
				<el-table :data="teamList"   style="width: 100%"> 
					<el-table-column  type="index" width='80'>
					</el-table-column>						 	
				 	<el-table-column prop="name" label="小组">
				    </el-table-column>
				 	<el-table-column prop="roadCommitTime" label="作业提交时间">
				    </el-table-column>
				 	<el-table-column prop="roadPublishTime" label="作业评分时间">
				    </el-table-column>
				 	<el-table-column prop="isRoadCommitted" label="提交状态">
				 		<template scope="scope">
				 			<p>{{scope.row.isRoadCommitted?'已提交':'未提交'}}</p>
				 		</template>
				    </el-table-column>		
				 	<el-table-column prop="isRoadPublished" label="评分状态">
				 		<template scope="scope">
				 			<p>{{scope.row.isRoadPublished?'已评分':'未评分'}}</p>
				 		</template>				 		
				    </el-table-column>	
				 	<el-table-column prop="roadScore" label="分数">
				   </el-table-column>	
					<el-table-column label="操作">
						<template scope="scope">
							<el-button size="small" v-if="scope.row.isRoadCommitted&&!scope.row.isRoadPublished" @click="Roadskip('/taskstage',$route.query.id,scope.row.teamId,'4',scope.row)" type="warning">评分</el-button>
							<el-button size="small" v-if="scope.row.isRoadPublished&&scope.row.isRoadCommitted" @click="Roadskip('/taskstage',$route.query.id,scope.row.teamId,'4',scope.row)" type="danger">已评分</el-button>	
							<el-button size="small" v-if="!scope.row.isRoadCommitted"   type="success">未提交</el-button>							
						</template>					
					</el-table-column>
				</el-table>				
			</el-col>			
			<!--工具-->
			<el-col :span="24" class="toolbar">
				<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="10" :total="total" style="float:right;">
				</el-pagination>
			</el-col>				
		</div>
	</section>
</template>

<script>
	import {courseStupi,coursunitget,courseTeam} from '../../api/api'
	 export default {
	 	data(){
	 		return{
				UnitInfo:{},
				List:[],
				teamList:[],
				pageSize:"10",
				pageNum:"1",
				total:"",
	 		}
	 	},
	 	methods:{
		    skip(link,id,unitId,stage,userId,user){
		    	localStorage.setItem('taskuser',JSON.stringify(user))
		        this.$router.push(
		        	{
		        		path:link,
		        		query:{
		        			id:id,
		        			unitId:unitId,
		        			stage:stage,
		        			userId:userId
		        		}
		        	}
		        )
		    },	
		    Roadskip(link,id,teamId,stage,row){
		    	localStorage.setItem('taskuser',JSON.stringify(row))
		        this.$router.push(
		        	{
		        		path:link,
		        		query:{
		        			id:id,
		        			teamId:teamId,
		        			stage:stage,
		        		}
		        	}
		        )
		    },			    
			handleCurrentChange(val) {
				this.pageNum = val;
				this.getCourseStudent();
			},	
			StageCurrentChange(val) {
				this.pageNum = val;
				this.getTeam();
			},			
		    getStageInfo:function(){
		    	coursunitget(this.$route.query.unitId).then((res)=>{
	    		
		    		this.UnitInfo=res
		    	})
		    },	    
		    getCourseStudent:function(){
		    	var param={courseId:this.$route.query.id,unitId:this.$route.query.unitId,pageSize:this.pageSize,pageNum:this.pageNum};
		    	courseStupi(param).then((res)=>{
		    		this.total=res.total
					this.List=res.list
		    	})
		    },
			getTeam:function(){	
				let params={courseId:this.$route.query.id,pageSize:this.pageSize,pageNum:this.pageNum};
				var _this=this;
				courseTeam(params).then((res) => {
					_this.teamList=res.list;
				});				
			},		    
	 	},
		mounted() {
			var _this=this
			if(this.$route.query.stage==1||this.$route.query.stage==2){
				this.getStageInfo()
			}else{
	    		if(_this.$route.query.stage==3){
	    			_this.UnitInfo.name="沙盘推演"
	    		}
	    		if(_this.$route.query.stage==4){
	    			_this.UnitInfo.name="项目路演"
	    		}
				this.getTeam()
			}
			this.getCourseStudent()
			
		}  	 	
	 }
</script>
